<template>
  <div id="airports">
    <div class="card">
      <div class="card-body">
        <form class="row">
          <div class="col-1">
            <input
              type="textfield"
              class="form-control"
              placeholder="出发城市"
              size="8"
              v-model.trim="dcity"
            />
          </div>
          <div class="col-1">
            <input
              type="textfield"
              class="form-control"
              placeholder="到达城市"
              size="8"
              v-model.trim="acity"
            />
          </div>
          <div class="col-1">
            <input
              type="textfield"
              class="form-control"
              placeholder="航班号"
              size="8"
              v-model.trim="flightNo"
            />
          </div>
          <div class="col-1">
            <button
              type="button"
              class="btn btn-primary"
              @click.stop="search()"
            >
              查找
            </button>
            <button
              type="button"
              class="btn btn-secondary btn-sm ms-2"
              @click.stop="reset()"
            >
              重置
            </button>
          </div>
        </form>
      </div>
    </div>
    <table class="table table-striped table-hover table-sm small">
      <thead>
        <tr>
          <th>出发城市</th>
          <th>到达城市</th>
          <th>航班号</th>
          <th>出发机场</th>
          <th>到达机场</th>
          <th>出发时间</th>
          <th>到达时间</th>
          <th>机型</th>
          <th>经停</th>
          <th>班次</th>
          <th>舱位</th>
          <th>生效日期</th>
          <th>失效日期</th>
          <th>更新时间</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="info in dataList" :key="info.id">
          <td>{{ info.dcity }}</td>
          <td>{{ info.acity }}</td>
          <td>{{ info.flightNo }} {{ info.codeShared }}</td>
          <td>{{ info.dport }}</td>
          <td>{{ info.aport }}</td>
          <td>{{ info.dtime }}</td>
          <td>{{ info.atime }}</td>
          <td>{{ info.aircraft }}</td>
          <td>{{ info.stopOver }}</td>
          <td>{{ info.schedule }}</td>
          <td>{{ info.allSubclass }}</td>
          <td>{{ info.effectDate }}</td>
          <td>{{ info.expireDate }}</td>
          <td>{{ info.createTime }}</td>
        </tr>
      </tbody>
    </table>
    <nav id="pagination-box" class="float-end">
      <my-pagination
        name="pagination"
        :row-count="sc.rowCount"
        :page-total="sc.pageTotal"
        :page-no="sc.pageNo"
        @next-page="nextPage"
        @prev-page="prevPage"
        @direct-page="directPage"
      ></my-pagination>
    </nav>
  </div>
</template>

<script>
import $ from "jquery";
import { searchAirlineSchedules } from "@/api/basic-data.js";
import MyPagination from "@/components/my-pagination.vue";

export default {
  components: {
    MyPagination,
  },
  data() {
    return {
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 50,
        pageTotal: 0,
      },
      dcity: "",
      acity: "",
      flightNo: "",

      dataList: [],
    };
  },
  mounted: function () {
    this.search();
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    search: function () {
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        dcity: this.dcity,
        acity: this.acity,
        flightNo: this.flightNo,
      };

      searchAirlineSchedules(params, (jsonResult) => {
        this.dataList = jsonResult.dataList;
        this.sc = jsonResult.page;
      });
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
    reset: function () {
      this.dcity = "";
      this.acity = "";
      this.flightNo = "";
    },
  },
};
</script>